package me.leiusual.sharing.ui.setting

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.repository.UserRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.ui.mine.model.ParamsPasswordUpdate
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * Create by leiusual on 2018/7/21
 */
class SettingPasswordViewModel @Inject constructor(
    private val userRepository: UserRepository
) : ViewModel() {

  private val _passwordUpdate = MutableLiveData<ParamsPasswordUpdate>()
  val passwordUpdate: LiveData<Data<Unit>> = Transformations.switchMap(_passwordUpdate) {
    userRepository.passwordUpdate(it).toLiveData()
  }

  fun passwordUpdate(passwordOld: String, passwordNew: String, passwordTwo: String) {
    _passwordUpdate.value = ParamsPasswordUpdate(passwordOld, passwordNew, passwordTwo)
  }
}